package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.mvp.model.PlaceOrderM;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.luck.easyrecyclerview.swipe.MyLayoutManager;

import java.util.ArrayList;
import java.util.List;

/**
 * author：luck
 * project：EasyFoodBatch
 * package：com.luck.easyfoodbatch.adapter
 * email：893855882@qq.com
 * data：16/9/29
 */
public class ConfirmCardAdapter extends RecyclerArrayAdapter<PlaceOrderM.DataBean> {
    private List<PlaceOrderM.DataBean> list = new ArrayList<>();
    private Context mContext;

    public OnClickCoupon onClickCoupon;

    public interface OnClickCoupon {
        void onCoupon(int index, int position, String order_id);
    }

    public ConfirmCardAdapter(Context context, List<PlaceOrderM.DataBean> list, OnClickCoupon onClickCoupon) {
        super(context);
        this.list = list;
        this.mContext = context;
        this.onClickCoupon = onClickCoupon;
    }

    public void setList(List<PlaceOrderM.DataBean> list) {
        this.list = list;
    }

    public List<PlaceOrderM.DataBean> getList() {
        return list;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewItemHolder(parent);
    }

    public class ViewItemHolder extends BaseViewHolder<PlaceOrderM.DataBean> {
        RecyclerView recyclerView;
        TextView tv_shop_name;

        public ViewItemHolder(ViewGroup parent) {
            super(parent, R.layout.shop_confirm_list_item);
            recyclerView = $(R.id.recyclerView);
            tv_shop_name = $(R.id.tv_shop_name);
            MyLayoutManager manager = new MyLayoutManager(mContext);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
            recyclerView.setLayoutManager(manager);
        }

        @Override
        public void setData(PlaceOrderM.DataBean data, int position) {
            PlaceOrderM.DataBean bean = list.get(position);
            String shop_name = bean.getShop_name();
            tv_shop_name.setText(shop_name);
            List<PlaceOrderM.DataBean.OrderInfoBean> orderInfo = bean.getOrderInfo();
            ConfirmShopCardAdapter adapter = new ConfirmShopCardAdapter(mContext, position, orderInfo, onCouponClick);
            recyclerView.setAdapter(adapter);
        }
    }

    /**
     * 选择优惠券回调
     */
    public ConfirmShopCardAdapter.OnCouponClick onCouponClick = new ConfirmShopCardAdapter.OnCouponClick() {
        @Override
        public void onCoupon(int index, int position, String order_id) {
            onClickCoupon.onCoupon(index, position, order_id);
        }
    };
}
